package com.admin.service;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.admin.dao.AdminOtherDao;
import com.common.model.AdminUser;
import com.common.model.Record;
import com.common.util.Md5Encrypt;

@Service
public class AdminOtherService {
	@Autowired
	@Qualifier("adminOtherDao")
	AdminOtherDao dao;
	
	public ArrayList<AdminUser> getAllAdmin(int page){
		if(page<1){
			page=1;
		}
		int start=(page-1)*10;
		return dao.getAllAdmin(start);
	}
	public int getAllAdminCount(){
		return dao.getAllAdminCount();
	}
	/**
	 * 新建一个管理员
	 * @param admin
	 * @return
	 */
	public int insertNewAdmin(AdminUser admin){
		if(admin.getCollegeId()==0){
			admin.setSuperAdmin(true);
			admin.setCollegeId(null);
		}else{
			admin.setSuperAdmin(false);
		}
		return dao.insertNewAdmin(admin);
	}
	public  ArrayList<AdminUser> getAdminByAdminNo(String no){
		return dao.getAdminByAdminNo(no);
	}
	public  AdminUser getAdminByAdminId(int adminId){
		return dao.getAdminByAdminId(adminId);
	}
	/**
	 * 删除一个管理员
	 * @param adminId
	 * @return
	 */
	public int deleteAdmin(int adminId){
		return dao.deleteAdmin(adminId);
	}
	/**
	 * 修改一个管理员
	 * @param adminId
	 * @return
	 */
	public int updateAdmin(AdminUser admin){
		if(admin.getCollegeId()==0){
			admin.setSuperAdmin(true);
			admin.setCollegeId(null);
		}else{
			admin.setSuperAdmin(false);
		}
		return dao.updateAdmin(admin);
	}
	/**
	 * 重置密码
	 * @param id
	 * @param pass
	 * @return
	 */
	public int resetAdminPass(int id,String pass){
		return dao.resetAdminPass(id,Md5Encrypt.encrypt(pass));
	}
	public int backAndDelete(){
		return dao.backAndDelete();
	}
	public int deleteBack(){
		return dao.deleteBack();
	}
	public int deleteTeacher(Integer clgId){
		return dao.deleteTeacher(clgId);
	}

	public ArrayList<Record> getRecord(int page){
		if(page<1){
			page=1;
		}
		int start=(page-1)*10;
		return dao.getRecord(start);
	}
	public int getRecordCount(){
		return dao.getRecordCount();
	}
}
